package com.turing.data.scripts.contract.filter


import com.turing.common.util.FileUtils
import com.turing.common.util.StringUtils
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

class Trustee_30209_10_filter {

    static List< TaskElementVO.DrawResultVO > doConvert(DependParamsVO dependParams){

        def textPathMap = dependParams.textPathMap

        List<TaskElementVO.DrawResultVO> results = new ArrayList<>();

        def result = new ArrayList()
        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        for (drawResultVO in resultVOs) {
            if(StringUtils.isEmpty(drawResultVO.childTaskSn)){
                continue
            }
            def rawPath = textPathMap.get(drawResultVO.childTaskSn)
            def rawText = FileUtils.loadJson(rawPath)
            def start = drawResultVO.start
            def end = drawResultVO.end
            def expandOffset = 0
            while( expandOffset < 20 && start > expandOffset ){
                def expandStr = rawText.substring(start-expandOffset,start)
                if(expandStr =~ /.*托管人.*/){
                    results.add(drawResultVO)
                    return results
                }
                expandOffset++
            }
        }

        if ((result == null || result.size() <= 0) && resultVOs.size() > 0) {
            return  resultVOs
        }
        return results

    }

}
